<?php
require_once 'CMS/Util.php';
require_once 'CMS/Mvc/BaseController.php';
require_once 'CMS/Mvc/BaseUserController.php';
require_once 'CMS/UserCommon.php';
require_once 'CMS/Language.php';

//Người tạo : Nguyễn Huỳnh Đại Thành - Team 3
//Module 	: Lastest QA
//Chức năng	: Show ra tất cả những QA mới update

class SlideShow_IndexController {

	public function init(){
		parent::init();
	}

	public function indexAction()
	{
		/*========== Start Load Language ==========*/
		$language = new Language(APPLICATION_PATH . '/widgets/slideshow');
		if(isset($_SESSION['language']))
		{
			$language_id = $_SESSION['language'];
			$tbLanguage = new Language_Model_Language();
			$name = $tbLanguage->getNameLanguage($language_id);
			$language->load($name['name']);
		}
		else
			$language->load('Default');		
		/*========== End Load Language ==========*/
			
			
		/*========== Start Get Text ==============*/
		$this->view->textReadMore 	= $language->get('text_readmore');
		$this->view->textNext 		= $language->get('text_next');
		$this->view->textPrevious 	= $language->get('text_previous');
		$this->view->textNoNew 		= $language->get('text_nonew');
		/*========== End Text ==============*/		
		
		//Start------Check Input Parameter
		$path = APPLICATION_PATH."/widgets/slideshow/";
		$xmlconfig = new SimpleXMLElement($path."config.xml",null,true);//Read config.xml
		//End--------Check Input Parameter
		
		//Start------Khai báo các parameter
		$tbThings= new SlideShow_Model_Things();
		//End--------Khai báo các parameter
		/************ Start check user login *********/
		$session1 = new Zend_Session_Namespace('login.auth');
		if(isset($session1->id_user))
		{
			$this->view->login = "1";
			/************ Start check permission *********/
			$user = new User();
			$user->init();
			$hasmodify = $user->modifiy_content($xmlconfig->name);
			$this->view->permission = $hasmodify;
			/************ End check user permission *********/
		}
		else 
		{
			
			$this->view->login = "0";
		}
		/************ End check user login *********/
		
		$News=0;
		$limit= 9;	
		$News=$tbThings->getLastest($limit,2); 
		$i = 0;
		foreach($News as $New)
		{
			$decription_lang=unserialize($New["description"]);
			$title_lang=unserialize($New["title"]);
			if (isset($decription_lang[$name['name']]))
				$News[$i]["description"]=$decription_lang[$name['name']];
			else
				$News[$i]["description"]="-----------------------";
			
			if (isset($title_lang[$name['name']]))
				$News[$i]["title"]=$title_lang[$name['name']];
			else
				$News[$i]["title"]="...";
				$i++;
		}
		//Start------Truyền parameter qua View
		//start---truyen title
        $titleXML = 'title'.$name['name'];
        if(isset($xmlconfig->$titleXML))
        	$this->view->title = $xmlconfig->$titleXML;
        else
        	$this->view->title = $xmlconfig->titleDefault;
		//end---truyen title
		$this->view->News=$News;
	}
		
}